generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 481
Transform invalid tool usages on sending, not on initial detection #1091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+223
−5
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Per bug strands-agents#1069, session-managers never persist tool-name changes after we initially persist the message, which means once an agent generates an invalid-tool name, that message history is poisoned on re-hydration. To avoid that going forward, do the translation of invalid-tool names on sending to the provider and not on the initial tool_use detection. The initial tool_use detection is needed to add a tool_response with a proper error message for the LLM, but this will avoid the poisoning issue
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Member
dbschmigelski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slow clap for the PR description
pgrayy
reviewed
Oct 27, 2025
Unshure
reviewed
Oct 27, 2025
pgrayy
approved these changes
Oct 28, 2025
dbschmigelski
approved these changes
Oct 28, 2025
3 tasks
dbschmigelski
pushed a commit
to schnetler/sdk-python
that referenced
this pull request
Nov 12, 2025
…trands-agents#1091) Per bug strands-agents#1069, session-managers never persist tool-name changes after we initially persist the message, which means once an agent generates an invalid-tool name, that message history is poisoned on re-hydration. To avoid that going forward, do the translation of invalid-tool names on sending to the provider and not on the initial tool_use detection. The initial tool_use detection is needed to add a tool_response with a proper error message for the LLM, but this will avoid the poisoning issue --------- Co-authored-by: Mackenzie Zastrow <zastrowm@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Some background context:
This is the follow up to the first pr (#1087) and is a 2nd part fix to #1069.
Per the bug, session-managers never persist tool-name changes after the initial persisting of the message, which means once an agent generates an invalid-tool name, that message history is poisoned on re-hydration. To avoid that going forward, do the translation of invalid-tool names on sending to the provider and not on the initial tool_use detection. The initial tool_use detection is still needed to add a tool_response with a proper error message for the LLM, but the tool name change is now done elsewhere to avoid the poisoning issue
Previous behavior
Prior to both bug fixes, this was the problem:
event_loop._handle_tool_executionwhich callsvalidate_and_prepare_toolsis invoked. The validation fails which has two side-effects:INVALID_TOOL_NAMEBug # 1 was fixed in #1087, and this is now the fix for Bug # 2
Notes
Related Issues
#1069
Documentation PR
N/A
Type of Change
Bug fix
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.